package com.example.tasktable.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

//SessionUtil方法打包
public class SqlSessionUtil {
    public static SqlSession GetSession() throws IOException {
        try {
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            return sqlSessionFactory.openSession();
        } catch (Exception e) {
            System.out.println("发生严重错误！！！SqlSessionUtil异常,错误原因:" + e.getMessage());
            System.exit(0);
            return null;
        }
    }

}
